﻿namespace HRM.CORE.Candidate
{
    using APP.HELPER.Utils.Language;
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmMark : XtraForm
    {
        private SimpleButton btClose;
        private SimpleButton btSaveClose;
        private CalcEdit calMark1;
        private CalcEdit calMark2;
        private CalcEdit calMark3;
        private CheckEdit chIsPass;
        private IContainer components;
        private DateEdit dtDate1;
        private DateEdit dtDate2;
        private DateEdit dtDate3;
        private GroupControl grInformation;
        protected DevExpress.Utils.ImageCollection imageCollection2;
        private LabelControl lcComment;
        private LabelControl lcDate1;
        private LabelControl lcDate2;
        private LabelControl lcDate3;
        private LabelControl lcMark1;
        private LabelControl lcMark2;
        private LabelControl lcMark3;
        private string m_CandidateCode;
        private MemoEdit txtComment;

        public event SuccessEventHander Success;

        public xfmMark()
        {
            this.components = null;
            this.m_CandidateCode = "";
            this.InitializeComponent();
            this.InitMultiLanguages();
        }

        public xfmMark(string CandidateCode)
        {
            this.components = null;
            this.m_CandidateCode = "";
            this.InitializeComponent();
            this.InitMultiLanguages();
            this.m_CandidateCode = CandidateCode;
            this.Init();
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btSaveClose_Click(object sender, EventArgs e)
        {
            HRM_CANDIDATE_MARK hrm_candidate_mark = new HRM_CANDIDATE_MARK {
                MarkID = Guid.NewGuid(),
                CandidateCode = this.m_CandidateCode,
                Mark1 = double.Parse(this.calMark1.Text),
                Mark2 = double.Parse(this.calMark2.Text),
                Mark3 = double.Parse(this.calMark3.Text),
                Date1 = DateTime.Parse(this.dtDate1.Text),
                Date2 = DateTime.Parse(this.dtDate2.Text),
                Date3 = DateTime.Parse(this.dtDate3.Text),
                Comment = this.txtComment.Text,
                IsPass = this.chIsPass.Checked
            };
            if (hrm_candidate_mark.Update() == "OK")
            {
                base.Close();
                HRM_CANDIDATE hrm_candidate = new HRM_CANDIDATE();
                hrm_candidate.Get(this.m_CandidateCode);
                if (hrm_candidate.Status == 4)
                {
                    this.RaiseSuccessEventHander(4);
                }
                else
                {
                    HRM_CANDIDATE_RATE hrm_candidate_rate = new HRM_CANDIDATE_RATE();
                    if (hrm_candidate_rate.Get(this.m_CandidateCode) != "OK")
                    {
                        hrm_candidate.UpdateStatus(this.m_CandidateCode, 1);
                        this.RaiseSuccessEventHander(1);
                    }
                    else if (!(hrm_candidate_mark.IsPass || hrm_candidate_rate.IsPass))
                    {
                        hrm_candidate.UpdateStatus(this.m_CandidateCode, 0);
                        this.RaiseSuccessEventHander(0);
                    }
                    else if (!(!hrm_candidate_mark.IsPass || hrm_candidate_rate.IsPass))
                    {
                        hrm_candidate.UpdateStatus(this.m_CandidateCode, 1);
                        this.RaiseSuccessEventHander(1);
                    }
                    else if (!(hrm_candidate_mark.IsPass || !hrm_candidate_rate.IsPass))
                    {
                        hrm_candidate.UpdateStatus(this.m_CandidateCode, 2);
                        this.RaiseSuccessEventHander(2);
                    }
                    else if (hrm_candidate_mark.IsPass && hrm_candidate_rate.IsPass)
                    {
                        hrm_candidate.UpdateStatus(this.m_CandidateCode, 3);
                        this.RaiseSuccessEventHander(3);
                    }
                }
            }
            else
            {
                MessageBox.Show("Cập nhật điểm thi thất bại!");
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void groupControl1_Paint(object sender, PaintEventArgs e)
        {
        }

        private void Init()
        {
            this.dtDate1.DateTime = DateTime.Now;
            this.dtDate2.DateTime = DateTime.Now;
            this.dtDate3.DateTime = DateTime.Now;
            HRM_CANDIDATE hrm_candidate = new HRM_CANDIDATE();
            hrm_candidate.Get(this.m_CandidateCode);
            this.grInformation.Text = "Nhập kết quả thi tuyển - " + hrm_candidate.FirstName + " " + hrm_candidate.LastName + " (" + hrm_candidate.CandidateCode + ")";
            HRM_CANDIDATE_MARK hrm_candidate_mark = new HRM_CANDIDATE_MARK();
            hrm_candidate_mark.Get(this.m_CandidateCode);
            if (hrm_candidate_mark != null)
            {
                this.calMark1.EditValue = hrm_candidate_mark.Mark1;
                this.calMark2.EditValue = hrm_candidate_mark.Mark2;
                this.calMark3.EditValue = hrm_candidate_mark.Mark3;
                this.dtDate1.EditValue = hrm_candidate_mark.Date1;
                this.dtDate2.EditValue = hrm_candidate_mark.Date2;
                this.dtDate3.EditValue = hrm_candidate_mark.Date3;
                this.txtComment.Text = hrm_candidate_mark.Comment;
                this.chIsPass.EditValue = hrm_candidate_mark.IsPass;
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmMark));
            this.grInformation = new GroupControl();
            this.lcDate3 = new LabelControl();
            this.lcDate2 = new LabelControl();
            this.lcComment = new LabelControl();
            this.lcDate1 = new LabelControl();
            this.lcMark3 = new LabelControl();
            this.lcMark2 = new LabelControl();
            this.lcMark1 = new LabelControl();
            this.txtComment = new MemoEdit();
            this.dtDate3 = new DateEdit();
            this.dtDate2 = new DateEdit();
            this.dtDate1 = new DateEdit();
            this.calMark3 = new CalcEdit();
            this.calMark2 = new CalcEdit();
            this.calMark1 = new CalcEdit();
            this.btClose = new SimpleButton();
            this.imageCollection2 = new DevExpress.Utils.ImageCollection(this.components);
            this.btSaveClose = new SimpleButton();
            this.chIsPass = new CheckEdit();
            this.grInformation.BeginInit();
            this.grInformation.SuspendLayout();
            this.txtComment.Properties.BeginInit();
            this.dtDate3.Properties.VistaTimeProperties.BeginInit();
            this.dtDate3.Properties.BeginInit();
            this.dtDate2.Properties.VistaTimeProperties.BeginInit();
            this.dtDate2.Properties.BeginInit();
            this.dtDate1.Properties.VistaTimeProperties.BeginInit();
            this.dtDate1.Properties.BeginInit();
            this.calMark3.Properties.BeginInit();
            this.calMark2.Properties.BeginInit();
            this.calMark1.Properties.BeginInit();
            this.imageCollection2.BeginInit();
            this.chIsPass.Properties.BeginInit();
            base.SuspendLayout();
            this.grInformation.Controls.Add(this.lcDate3);
            this.grInformation.Controls.Add(this.lcDate2);
            this.grInformation.Controls.Add(this.lcComment);
            this.grInformation.Controls.Add(this.lcDate1);
            this.grInformation.Controls.Add(this.lcMark3);
            this.grInformation.Controls.Add(this.lcMark2);
            this.grInformation.Controls.Add(this.lcMark1);
            this.grInformation.Controls.Add(this.txtComment);
            this.grInformation.Controls.Add(this.dtDate3);
            this.grInformation.Controls.Add(this.dtDate2);
            this.grInformation.Controls.Add(this.dtDate1);
            this.grInformation.Controls.Add(this.calMark3);
            this.grInformation.Controls.Add(this.calMark2);
            this.grInformation.Controls.Add(this.calMark1);
            this.grInformation.Dock = DockStyle.Top;
            this.grInformation.Location = new Point(0, 0);
            this.grInformation.Name = "grInformation";
            this.grInformation.Size = new Size(0x15a, 0xe9);
            this.grInformation.TabIndex = 0;
            this.grInformation.Text = "Nhập kết quả thi tuyển";
            this.lcDate3.Location = new Point(0xa7, 0x5b);
            this.lcDate3.Name = "lcDate3";
            this.lcDate3.Size = new Size(0x2c, 13);
            this.lcDate3.TabIndex = 10;
            this.lcDate3.Text = "Ng\x00e0y thi:";
            this.lcDate2.Location = new Point(0xa7, 60);
            this.lcDate2.Name = "lcDate2";
            this.lcDate2.Size = new Size(0x2c, 13);
            this.lcDate2.TabIndex = 6;
            this.lcDate2.Text = "Ng\x00e0y thi:";
            this.lcComment.Location = new Point(0x17, 0x77);
            this.lcComment.Name = "lcComment";
            this.lcComment.Size = new Size(0x2f, 13);
            this.lcComment.TabIndex = 12;
            this.lcComment.Text = "Đ\x00e1nh gi\x00e1:";
            this.lcDate1.Location = new Point(0xa7, 0x20);
            this.lcDate1.Name = "lcDate1";
            this.lcDate1.Size = new Size(0x2c, 13);
            this.lcDate1.TabIndex = 2;
            this.lcDate1.Text = "Ng\x00e0y thi:";
            this.lcMark3.Location = new Point(0x16, 0x59);
            this.lcMark3.Name = "lcMark3";
            this.lcMark3.Size = new Size(0x40, 13);
            this.lcMark3.TabIndex = 8;
            this.lcMark3.Text = "Điểm v\x00f2ng 3:";
            this.lcMark2.Location = new Point(0x17, 0x3b);
            this.lcMark2.Name = "lcMark2";
            this.lcMark2.Size = new Size(0x40, 13);
            this.lcMark2.TabIndex = 4;
            this.lcMark2.Text = "Điểm v\x00f2ng 2:";
            this.lcMark1.Location = new Point(0x17, 0x20);
            this.lcMark1.Name = "lcMark1";
            this.lcMark1.Size = new Size(0x40, 13);
            this.lcMark1.TabIndex = 0;
            this.lcMark1.Text = "Điểm v\x00f2ng 1:";
            this.txtComment.Location = new Point(90, 0x74);
            this.txtComment.Name = "txtComment";
            this.txtComment.Size = new Size(0xf4, 0x6b);
            this.txtComment.TabIndex = 13;
            this.dtDate3.EditValue = null;
            this.dtDate3.Location = new Point(0xd9, 0x58);
            this.dtDate3.Name = "dtDate3";
            this.dtDate3.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate3.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate3.Size = new Size(0x75, 20);
            this.dtDate3.TabIndex = 11;
            this.dtDate2.EditValue = null;
            this.dtDate2.Location = new Point(0xd9, 0x39);
            this.dtDate2.Name = "dtDate2";
            this.dtDate2.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate2.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate2.Size = new Size(0x75, 20);
            this.dtDate2.TabIndex = 7;
            this.dtDate1.EditValue = null;
            this.dtDate1.Location = new Point(0xd9, 30);
            this.dtDate1.Name = "dtDate1";
            this.dtDate1.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate1.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate1.Size = new Size(0x75, 20);
            this.dtDate1.TabIndex = 3;
            this.calMark3.Location = new Point(90, 0x56);
            this.calMark3.Name = "calMark3";
            this.calMark3.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calMark3.Size = new Size(0x3e, 20);
            this.calMark3.TabIndex = 9;
            this.calMark2.Location = new Point(90, 0x38);
            this.calMark2.Name = "calMark2";
            this.calMark2.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calMark2.Size = new Size(0x3e, 20);
            this.calMark2.TabIndex = 5;
            this.calMark1.Location = new Point(90, 0x1c);
            this.calMark1.Name = "calMark1";
            this.calMark1.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calMark1.Size = new Size(0x3e, 20);
            this.calMark1.TabIndex = 1;
            this.btClose.ImageIndex = 2;
            this.btClose.ImageList = this.imageCollection2;
            this.btClose.Location = new Point(0xf8, 0xf1);
            this.btClose.Name = "btClose";
            this.btClose.Size = new Size(0x56, 0x17);
            this.btClose.TabIndex = 3;
            this.btClose.Text = "Đ\x00f3ng";
            this.btClose.Click += new EventHandler(this.btClose_Click);
            this.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.btSaveClose.ImageIndex = 0;
            this.btSaveClose.ImageList = this.imageCollection2;
            this.btSaveClose.Location = new Point(0x86, 0xf1);
            this.btSaveClose.Name = "btSaveClose";
            this.btSaveClose.Size = new Size(0x6c, 0x17);
            this.btSaveClose.TabIndex = 2;
            this.btSaveClose.Text = "Lưu V\x00e0 Đ\x00f3ng";
            this.btSaveClose.Click += new EventHandler(this.btSaveClose_Click);
            this.chIsPass.Location = new Point(14, 0xf1);
            this.chIsPass.Name = "chIsPass";
            this.chIsPass.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.chIsPass.Properties.Appearance.Options.UseFont = true;
            this.chIsPass.Properties.Caption = "Đậu thi tuyển";
            this.chIsPass.Size = new Size(0x67, 0x13);
            this.chIsPass.TabIndex = 1;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x15a, 0x10d);
            base.Controls.Add(this.chIsPass);
            base.Controls.Add(this.btSaveClose);
            base.Controls.Add(this.btClose);
            base.Controls.Add(this.grInformation);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmMark";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Kết Quả Thi Tuyển";
            this.grInformation.EndInit();
            this.grInformation.ResumeLayout(false);
            this.grInformation.PerformLayout();
            this.txtComment.Properties.EndInit();
            this.dtDate3.Properties.VistaTimeProperties.EndInit();
            this.dtDate3.Properties.EndInit();
            this.dtDate2.Properties.VistaTimeProperties.EndInit();
            this.dtDate2.Properties.EndInit();
            this.dtDate1.Properties.VistaTimeProperties.EndInit();
            this.dtDate1.Properties.EndInit();
            this.calMark3.Properties.EndInit();
            this.calMark2.Properties.EndInit();
            this.calMark1.Properties.EndInit();
            this.imageCollection2.EndInit();
            this.chIsPass.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.Text = MultiLanguages.GetString("tbl_CandidateMark", "Title", this.Text);
            this.grInformation.Text = MultiLanguages.GetString("tbl_CandidateMark", "grInformation", this.grInformation.Text);
            this.lcMark1.Text = MultiLanguages.GetString("tbl_CandidateMark", "Mark1", this.lcMark1.Text);
            this.lcMark2.Text = MultiLanguages.GetString("tbl_CandidateMark", "Mark2", this.lcMark2.Text);
            this.lcMark3.Text = MultiLanguages.GetString("tbl_CandidateMark", "Mark3", this.lcMark3.Text);
            this.lcDate1.Text = MultiLanguages.GetString("tbl_CandidateMark", "Date1", this.lcDate1.Text);
            this.lcDate2.Text = MultiLanguages.GetString("tbl_CandidateMark", "Date2", this.lcDate2.Text);
            this.lcDate3.Text = MultiLanguages.GetString("tbl_CandidateMark", "Date3", this.lcDate3.Text);
            this.lcComment.Text = MultiLanguages.GetString("tbl_CandidateMark", "Comment", this.lcComment.Text);
            this.chIsPass.Text = MultiLanguages.GetString("tbl_CandidateMark", "IsPass", this.chIsPass.Text);
            this.btSaveClose.Text = MultiLanguages.GetString("tbl_CandidateMark", "SaveAndClose", this.btSaveClose.Text);
            this.btClose.Text = MultiLanguages.GetString("tbl_CandidateMark", "Close", this.btClose.Text);
        }

        private void RaiseSuccessEventHander(int value)
        {
            if (this.Success != null)
            {
                this.Success(this, value);
            }
        }

        public delegate void SuccessEventHander(object sender, int value);
    }
}

